<template>
	<!-- 车辆体检 -->
	<view>
		<view class="orange-father">
			<view class="orange-tip">
				<view class="text_1">1.影响车辆实时健康状态因素较多，该检测结果仅供参考</view>
				<view class="text_1">2.使用体检功能，请确保车辆与之欧能设备处于工作状态，便于获取车辆最新故障信息；</view>
				<view class="text_1">3.体检结果若出现故障，请勿过于紧张。需加强对车辆车况观察，并尝试一天多次体检，若故障无法自主修复，请按照修复建议完成故障处理。</view>
			</view>
			<view class="orange_bg">
				<!-- <view class="gradient_bg"></view> -->
				<image class="logo_bg" src="@appstatic/car/car_check_bg.png" />
				<view class="check_info_view" v-if="isGetData">
					<view class="check_info">
						<view class="score" style="margin-bottom: 13rpx;">
							<view class="text_2">
								{{totalScore}}
							</view>
							<view class="text_3" style="margin-left: 8rpx;">
								分
							</view>
						</view>
						<view class="check_msg" v-if="isCheckSuccess">
							<view class="text_4">
								{{checkMsg}}
							</view>
							<view class="text_4">
								数据统计时间：{{checkTime}}
							</view>
						</view>
						<view class="check_msg" v-else>
							<view class="text_5">
								正在检测请稍后
							</view>
							<view class="text_4" style="visibility:hidden">
								数据统计时间：
							</view>
						</view>

					</view>




					<view class="cleckBtn" @click="carCheck()">
						立即体检
					</view>

				</view>
				<view class="check_info_view" v-else>
					<view class="text_6">正在获取数据...</view>
				</view>


			</view>




		</view>
		<block :key="index" v-for="(item,index) in checkList" v-if="isGetData">
			<view class="horizontal">
				<view class="dot-line-view">
					<view class="date-line"></view>
					<image class="small_icon" src="@appstatic/car/car_check_grey_dot.png" />
					<view class="date-line"></view>
				</view>
				<view class="text_8">{{item.faultSystem}}</view>
			</view>
			<block :key="index" v-for="(item1,index1) in item.faultList">
				<view class="horizontal">
					<view class="dot-line-view">
						<view class="date-line"></view>
						<!-- <image class="small_icon" src="@appstatic/car/car_check_grey_dot.png" /> -->
						<view class="date-line"></view>
					</view>
					<view class="faultView">
						<view class="text_8" >{{item1.faultCode}}</view>
						<view class="text_8" style="margin-left: 16rpx;" >{{item1.faultName}}</view>
					</view>
					 
					
				</view>
			</block>
		</block>

		<u-modal :show="showTips" @confirm="clickNotice" width='315px' confirmColor="#EA5404" confirmText="我知道了">
			<view style="width: 267px;">
				<view class="text_7">1.车辆体检时，请确保车辆与智能设备处于工作状态，便于获取车辆最新的故障信息；</view>
				<view class="text_7">2.体检结果若出现故障，请加强对车辆车况观察，并尝试一天多次体检，已确定该故障无法自修复。</view>
			</view>
		</u-modal>








	</view>
</template>

<script>
	const app = getApp();
	const network = require("@/manager/network-manager.js");
	import moment from 'dayjs'
	export default {
		data() {
			return {
				showTips: false,
				isGetData: false,
				isCheckSuccess: false,
				checkMsg: '',
				checkTime: '',
				deviceId: '',

				totalScore: '',
				checkList: []
			}
		},
		onLoad() {
			this.showTips = true
			if (uni.getStorageSync('deviceId')) {
				this.deviceId = uni.getStorageSync('deviceId')
			}
		},
		methods: {
			//点击检测须知
			clickNotice: function() {
				this.showTips = false
				this.carCheck()
			},
			//车辆检查
			carCheck: function() {
				var that = this
				that.isGetData = false
				var uri = app.globalData.config.interfaces.URL_CMOBILE_VEHICLEINFO_GETCHECKFAULTSTATUS
				var params = {
					deviceId: that.deviceId
				}
				network.get(uri, params, 'form').then(res => {
					if (res.code == 200) {
						that.isGetData = true
						that.totalScore = res.data.totalScore
						that.checkList = res.data.dataList
						if (res.data.resultNote == "Success") {
							that.isCheckSuccess = true
							that.checkTime = res.data.canUpdatetime
						}
						var list = []
						for(var i = 0;i<that.checkList.length;i++){
							var itemList =that.checkList[i].faultList
							if(itemList.length>0){
								for(var j = 0;j<itemList.length;j++){
									list.push(itemList[j].suggestion)
								}
							}
							
						}
						if(list.length>0){
							that.checkMsg=list[0]
						}else{
							that.checkMsg='车况指数良好，请继续保持！'
							
						}
					}
				})
			}

		}
	}
</script>

<style>
	page {
		background-image: url(https://pfmotortest.hb4oss.xstore.ctyun.cn/appstatic/img/my_logo_bg.png);
		width: 100%;
		height: 100%;
		background-repeat: space;
		background-size: 100%;
	}

	.orange-father {
		position: sticky;
		top: 0;
		z-index: 100;
		background-color: #F5F5F5;
	}

	.orange-tip {
		display: flex;
		flex-direction: column;
		justify-content: flex-start;
		background: #EDEDED;
		padding-left: 32rpx;
		padding-right: 32rpx;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
	}



	.orange_bg {
		margin-top: 20rpx;
		margin-left: 32rpx;
		margin-right: 32rpx;
		width: 686rpx;
		height: 200rpx;
		background-color: #FF8D23;
		border-radius: 4px;
		display: flex;
		flex-direction: row;
		align-items: center;
		

	}

	.logo_bg {
		width: 686rpx;
		height: 200rpx;
		background-image: url('@appstatic/car/car_check_bg.png');
		border-radius: 4px;
		position: fixed;

	}

	.check_info_view {
		margin-top: 30rpx;
		margin-bottom: 30rpx;
		margin-left: 32rpx;
		margin-right: 32rpx;
		display: flex;
		flex-direction: row;
		height: 140rpx;
		justify-content: space-between;
		align-items: center;
		width: 100%;
	}

	.check_info {
		display: flex;
		flex-direction: column;
	}

	.check_msg {
		display: flex;
		flex-direction: column;
		align-items: flex-start;
	}

	.cleckBtn {
		height: 36px;
		box-sizing: border-box;
		line-height: 36px;
		font-size: 28rpx;
		color: #FFFFFF;
		border: 1px solid #FFFFFF;
		background-color: #00000000;
		padding-left: 32rpx;
		padding-right: 32rpx;
	}

	.score {
		display: flex;
		flex-direction: row;
		align-items: flex-end;
	}

	.horizontal {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
	}

	.dot-line-view {
		display: flex;
		flex-direction: column;
		margin-left: 25px;
		margin-right: 16px;

	}

	.date-line {
		border-left: 1px solid #ADB0AE;
		margin-left: 9rpx;
		height: 16px;

		width: 1px;
	}

	.small_icon {
		width: 10px;
		height: 10px;
	}

.faultView{
	display: flex;
	flex-direction: row;
	margin-left: 64rpx;
}

	.text_1 {
		font-weight: 400;
		font-size: 20rpx;
		line-height: 28rpx;
		color: #ADB0AE;
	}

	.text_2 {
		font-weight: 700;
		font-size: 48rpx;
		line-height: 56rpx;
		display: flex;
		align-items: center;
		text-align: right;
		color: #FFFFFF;
		text-shadow: 0px 0px 2px #F26203;
	}

	.text_3 {
		font-weight: 400;
		font-size: 32rpx;
		line-height: 46rpx;
		display: flex;
		align-items: center;
		color: #FFFFFF;
	}

	.text_4 {
		font-weight: 400;
		font-size: 24rpx;
		line-height: 34rpx;
		display: flex;
		align-items: center;
		color: #FFFFFF;
	}

	.text_5 {
		font-weight: 400;
		font-size: 24rpx;
		line-height: 34rpx;
		display: flex;
		align-items: center;
		color: #B95500;
	}

	.text_6 {
		font-weight: 400;
		font-size: 32rpx;
		line-height: 46rpx;
		color: #B95500;
	}

	.text_7 {
		ont-weight: 400;
		font-size: 28rpx;
		line-height: 42rpx;
		color: #333333;
		mix-blend-mode: normal;
		opacity: 0.9;
	}

	.text_8 {
		font-weight: 400;
		font-size: 28rpx;
		line-height: 40rpx;
		display: flex;
		align-items: center;
		color: #ADB0AE;
	}
</style>
